from time import sleep
from selenium import webdriver

# 打开浏览器-创建浏览器对象
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 打开浏览器
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome(executable_path='chromedriver.exe')

# 输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# driver = webdriver.Chrome()

# 放大浏览器
driver.maximize_window()

# 1）.点击 alert 按钮
# driver.find_element_by_css_selector("#alerta").click()

# 2）.关闭警告框
# driver.find_element_by_css_selector("#userA").send_keys("admin")





# ---------------取消-------------------
# 点击 alert 按钮
driver.find_element(By.CSS_SELECTOR, "#alerta").click()

# 获取弹框对象
al = driver.switch_to.alert

# 2）关闭警告框
al.dismiss()

# 3）输入用户名：admin
driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
sleep(2)
driver.close()